package cn.yllr.tomgxianghui.controller.admin;

import cn.yllr.tomgxianghui.entity.Dishes;
import cn.yllr.tomgxianghui.entity.Raw;
import cn.yllr.tomgxianghui.service.RawService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class Admin_RawController {
    @Resource
    RawService rawService;
//原材料列表
    @RequestMapping("/viewRaws")
    public String viewRaws(Model model){
        List<Raw> raws =rawService.queryAllRaws();
        model.addAttribute("raws",raws);
        return "admin/data-list";
    }
    //增加原材料
    @RequestMapping("/toAddRaws")
    public String toAddRaws(){
        return "admin/data-add";
    }
    @RequestMapping("/addRaws")
    public String addRaws(Raw raw){
        rawService.insert(raw);
        return "redirect:/viewRaws";
    }
    //修改原材料
    @RequestMapping("/toUpdateRaws/{id}")
    public String toUpdateRaws(@PathVariable("id")Integer id, Model model){
        Raw raw=rawService.queryById(id);
        model.addAttribute("raw",raw);
        return "admin/data-update";
    }
    @RequestMapping("/updateRaws")
    public String updateRaws(Raw raw){
        rawService.update(raw);
        return "redirect:/viewRaws";
    }
    //删除原材料
    @RequestMapping("/deleteRaws/{id}")
    public String deleteRaws(@PathVariable("id")Integer id){
        rawService.deleteById(id);
        return "redirect:/viewRaws";
    }
    //搜索原材料
    @RequestMapping("/searchRaws/{id}")
    public String searchDishes(@PathVariable("id")Integer id,Model model){
        Raw raw=rawService.queryById(id);
        model.addAttribute("raw",raw);
        return "admin/search-raw";
    }
}
